home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1299 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.1 KB

  1. Path: news.ov.com!news
  2. From: glenn@ov.com (Fletcher.Glenn@ov.com)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: warning: possibly incorrect assignment
  5. Date: 12 Jan 1996 21:47:19 GMT
  6. Organization: OpenVision
  7. Message-ID: <4d6kt7$542@spanky.pls.ov.com>
  8. References: <Pine.OSF.3.91.960109091920.6447A-100000@io.UWinnipeg.ca>
  9. Reply-To: glenn@ov.com
  10. NNTP-Posting-Host: foghorn.pls.ov.com
  11.  
  12. In article 100000@io.UWinnipeg.ca, Bill Simpson <wsimpson@uwinnipeg.ca> writes:
  13. >I get the above warning when I compile code using the following
  14. >function.  It flags the **** line.
  15. >
  16. >void save_data(unsigned long int time[],int n)
  17. >        {
  18. >        char file_name[30];
  19. >        double t;
  20. >        int i;
  21. >        FILE * fp;
  22. >
  23. >        printf("Enter file name: ");
  24. >        scanf("%s", file_name);
  25. >
  26. >****        while(fp=fopen(file_name,"r"))
  27.              while((fp = fopen(file_name, "r")) != NULL)
  28.  
  29. Try the above statement.
  30.  
  31. >                {
  32. >                printf("this file already exists--use another name\n");
  33. >                fclose(fp);
  34. >                printf("Enter filename:\n");
  35. >                scanf("%s", file_name);
  36. >                }
  37. >
  38. >        fp=fopen(file_name,"w"); 
  39. >        for (i=0;i<n;i++)
  40. >                {
  41. >                t=(double)time[i]/1000000; /*convert from microsec to sec*/
  42. >                fprintf(fp,"%.6f\n",t);
  43. >                }
  44. >        fclose(fp);                         
  45. >                                       
  46. >        return;
  47. >        }
  48. >
  49. >How can I write this code so the compiler does not issue this warning?
  50. >Please don't suggest I just tell the compiler to shut up.  In general
  51. >the warnings are useful.  I do not want to just ignore the warning either.
  52. >I have the FAQ and haven't seen this discussed.
  53. >
  54. >(Any other improvements to above code segment welcomed)
  55. >
  56. >Thanks very much for any help.
  57. >
  58. >Bill Simpson
  59.  
  60.  
  61.  
  62. Basically the compiler is complaining that there is an assignment
  63. in a conditional context, thinking you might mean ==.  If you
  64. encapsulate the assignment and then make a comparison, you are
  65. demonstrating that you really mean = and not ==.
  66.  
  67.             Fletcher.Glenn@ov.com
  68.  
  69.